from django.shortcuts import redirect


# 自定义判断是否登录的中间件
class UserLoginMiddle(object):
    # 没有调用视图函数前调用中间件
    def process_request(self,request):
        # 获取请求路径,判断请求的路径是哪个功能
        path = request.path
        if path in ['/user/user', '/user/order','/user/address']:
            if not request.user.is_authenticated():
                # HTTP_REFERER = request.META['HTTP_REFERER']是获取跳转前的路径
                # 登录成功后进入到拼接的路径中path
                return redirect('/user/login?next='+path)
